home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Utilities / Calc / lib / bigprime.cal < prev    next >
Encoding:
Text File  |  1992-02-24  |  565 b   |  31 lines  |  [TEXT/????]

  1. /*
  2.  * Copyright (c) 1992 David I. Bell
  3.  * Permission is granted to use, distribute, or modify this source,
  4.  * provided that this copyright notice remains intact.
  5.  *
  6.  * A prime test, base a, on p*2^x+1 for even x>m.
  7.  */
  8.  
  9. define bigprime(a, m, p)
  10. {
  11.     local n1, n;
  12.  
  13.     n1 = 2^m * p;
  14.     for (;;) {
  15.         m++;
  16.         n1 += n1;
  17.         n = n1 + 1;
  18.         if (isodd(m))
  19.             continue;
  20.         print m;
  21.         if (pmod(a, n1 / 2, n) != n1)
  22.             continue;
  23.         if (pmod(a, n1 / p, n) == 1)
  24.             continue;
  25.         print "    " : n;
  26.     }
  27. }
  28.  
  29. global lib_debug;
  30. if (!isnum(lib_debug) || lib_debug>0) print "bigprime(a, m, p) defined";
  31.